package com.xlh.fgs;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.wzm.param.ApiResultPo.AddUserReslult;
import com.xlh.Utils.GsonManager;
import com.xlh.lib.Core.FIntent;
import com.xlh.outside.LoginActivity;
import com.xlh.outside.MainActivity;
import com.xlh.outside.R;
import com.xlh.outside.ServerListActivity;

/**
 * 创建角色页面
 */

public class CreateRoleFg extends Fragment {


	private Context context;

	public CreateRoleFg() {
		// TODO Auto-generated constructor stub
	}

	public static final String TAG = CreateRoleFg.class.getName();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.create_role, container, false);
	}



		@Override
		public void onViewCreated(final View view, Bundle savedInstanceState) {
			// TODO Auto-generated method stub


		cEditNickName = (EditText)view.findViewById(R.id.edt_user_reg_nickname);
		cbutSubmit      = (Button)view.findViewById(R.id.reg_but_submit);
		cButback      = (Button)view.findViewById(R.id.reg_but_back);
		cRadio        = (RadioGroup)view.findViewById(R.id.reg_rd_sex);
		context 	  = view.getContext();
		//默认值
		setSex("男性");

		//Toast.makeText(view.getContext(), data.getMsg(), Toast.LENGTH_SHORT).show();


		cRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {


				int radioButtonId = group.getCheckedRadioButtonId();
				//根据ID获取RadioButton的实例
				RadioButton rb = (RadioButton) group.findViewById(radioButtonId);
				sex = rb.getText().toString();


			}
		});



		//back Button
		cButback.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				returnLogin();
			}
		});



		//提交按钮
		cbutSubmit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				String nickName;
				nickName = cEditNickName.getText().toString();
				//((MainActivity)context).getApp().setActiveUserSex(getSex());
				//arg,性别║头像║昵称。
				((MainActivity)context).sendActionToServer(String.format("%s,%s,%s",getSex(),"null",nickName));
			}
		});



	}




	public void returnLogin(){
		//进入相关游戏服
		FIntent fIntent = new FIntent(context, ServerListActivity.class);
		startActivity(fIntent);
		((MainActivity)context).finish();

	}


	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	/**
	 * 用户名控件
	 */

	private EditText cEditNickName;

	private Button cbutSubmit;
	private Button cbutReset;
	private Button cButback;
	private RadioGroup cRadio;
	private String sex;
	private Handler handler;



}
